home *** CD-ROM | disk | FTP | other *** search
- /***
- * main.c
- *
- * Tester routine for the URLHelper component. This routine will try to exercise all the
- * various facets of the component.
- *
- ***/
- #include "debug_me.h"
- #include "URLHelperComponent.h"
- #include "URLHelperComponentPrivate.h"
- #include <stdio.h>
- #include "Exceptions.h"
- #include "URLHLibrary.h"
-
- char *StrPrint (StringPtr string);
- void FullSub (ComponentInstance urlInstace, StringPtr string);
- void Lib1Sub (StringPtr string);
- void LibAllSub (StringPtr string);
-
- /**
- ** Global stuff we need if we are debugging -- this is because we have to supply
- ** all the info about the component when we register.
- **/
-
- #ifdef DEBUG_IT
- Handle gURLHelperNameHandle;
- Handle gURLHelperInfoHandle;
- #endif
-
- // Registration flags
- enum
- {
- kRegisterLocally = 0,
- kRegisterGlobally
- };
-
- void main () {
- ComponentInstance urlInstance;
- short numMirrors;
- URLHMirrorListRef infomacMirrors, archiveMirrors;
- OSErr theErr;
-
- #ifdef DEBUG_IT
- Component urlComponentID;
- ComponentDescription urlDesc;
- #endif
-
- /**
- ** Fill in the description of the URLHelper component
- **/
-
- #ifdef DEBUG_IT
- urlDesc.componentType = URLHelperComponentType;
- urlDesc.componentSubType = 0L;
- urlDesc.componentManufacturer = 'appl';
- urlDesc.componentFlags = 0L;
- urlDesc.componentFlagsMask = 0L;
-
- /**
- ** Fill in the info and the name for this component that we are going to register
- ** locally.
- **/
-
- {
- Str255 urlInfo = "\pThis component provides simple URLHelper services";
-
- gURLHelperInfoHandle = NewHandle (sizeof(Str255));
- BlockMove ((Ptr) &urlInfo, (Ptr) (*gURLHelperInfoHandle), urlInfo[0]+1);
- }
-
- {
- Str255 urlName = "\pURLHelper Reporter Component";
-
- gURLHelperNameHandle = NewHandle (sizeof(Str255));
- BlockMove ((Ptr) &urlName, (Ptr) (*gURLHelperNameHandle), urlName[0]+1);
- }
-
- /**
- ** Since this puppy is built to do debugging, we want to register the component
- ** locally, as opposed to getting it from the system during boot time.
- **/
-
- urlComponentID = RegisterComponent (&urlDesc, (ComponentRoutine) URLHelperDispatcher,
- kRegisterLocally, gURLHelperNameHandle, gURLHelperInfoHandle, 0L);
-
- /**
- ** Next, see if we can declare an instance of the damm thing
- **/
-
- urlInstance = OpenComponent (urlComponentID);
-
- #else
-
- /**
- ** Ok -- so we just need to open the component now
- **/
-
- urlInstance = OpenDefaultComponent (URLHelperComponentType, 0L);
- #endif
-
- if (urlInstance == 0)
- return;
-
- /**
- ** If the info-mac string list isn't there, then build it!
- **/
-
- theErr = URLHGetMirrorList (urlInstance, "\pinfo-mac", &infomacMirrors);
- if (theErr == errURLHNoSuchMirrorList) {
- printf ("Creating infomac mirror list...\n");
- theErr = URLHNewMirrorList (urlInstance, "\pinfo-mac", &infomacMirrors);
- nrequire (theErr, FailedToCreateIMMirror);
-
- theErr = URLHAddMirror (urlInstance, infomacMirrors,
- "\p^0://sumex-aim.stanford.edu/info-mac/^1", kURLHMNoUse);
- nrequire (theErr, FailedToAdd1);
-
- theErr = URLHAddMirror (urlInstance, infomacMirrors,
- "\p^0://mac.archive.edu/pub/info-mac/^1", kURLHMDefault);
- nrequire (theErr, FailedToAdd2);
-
- theErr = URLHAddMirror (urlInstance, infomacMirrors,
- "\p^0://mit.mit.edu/pub/mirrors/im/^1", kURLHMDefault);
- nrequire (theErr, FailedToAdd3);
-
- printf ("Creating mac.archive mirror list...\n");
- theErr = URLHNewMirrorList (urlInstance, "\pmac.archive", &archiveMirrors);
- nrequire (theErr, FailedToCreateArcMirror);
-
- theErr = URLHAddMirror (urlInstance, archiveMirrors,
- "\p^0://mac.archive.umich.edu/pub/^1", kURLHMDefault);
- nrequire (theErr, FailedToAdd4);
-
- theErr = URLHAddMirror (urlInstance, archiveMirrors,
- "\p^0://wustl.some.place.edu/pub/umich/^1", kURLHMDefault);
- nrequire (theErr, FailedToAdd5);
-
- theErr = URLHAddMirror (urlInstance, archiveMirrors,
- "\p^0://mit.mit.edu/pub/mirrors/marc/^1", kURLHMDefault);
- nrequire (theErr, FailedToAdd6);
-
- }
- nrequire (theErr, FailedToDoMirrorInit);
-
- /**
- ** See how many of these things are around...
- **/
-
- theErr = URLHNumberOfMirrors (urlInstance, infomacMirrors, &numMirrors);
- nrequire (theErr, FailedToCountMirrors);
- printf ("Number of mirrors in im: %d\n", numMirrors);
-
- theErr = URLHNumberOfMirrors (urlInstance, archiveMirrors, &numMirrors);
- nrequire (theErr, FailedToCountMirrors1);
- printf ("Number of mirrors in arc: %d\n", numMirrors);
-
- /**
- ** Now, given a random URL, loop over all the mirrors... :)
- **/
-
- FullSub (urlInstance,
- "\pftp://sumex-aim.stanford.edu/info-mac/grf/util/mac-graphics.hqx");
- FullSub (urlInstance,
- "\pgopher://sumex-aim.stanford.edu/info-mac/per/im/infomacv12-044.txt");
- FullSub (urlInstance,
- "\pgopher://mac.archive.umich.edu/pub/system/updates/long/dir/help.txt");
-
- URLHLibUse (urlInstance);
-
- Lib1Sub("\pftp://sumex-aim.stanford.edu/info-mac/grf/util/mac-graphics.hqx");
- Lib1Sub("\pgopher://sumex-aim.stanford.edu/info-mac/per/im/infomacv12-044.txt");
- Lib1Sub("\pgopher://mac.archive.umich.edu/pub/system/updates/long/dir/help.txt");
- LibAllSub("\pftp://sumex-aim.stanford.edu/info-mac/grf/util/mac-graphics.hqx");
- LibAllSub("\pgopher://sumex-aim.stanford.edu/info-mac/per/im/infomacv12-044.txt");
- LibAllSub("\pgopher://mac.archive.umich.edu/pub/system/updates/long/dir/help.txt");
-
- /**
- ** We are done!
- **/
-
- CloseComponent (urlInstance);
-
- return;
-
- FailedToFindIMList:
-
- FailedToCountMirrors:
- FailedToCountMirrors1:
- FailedToAdd1:
- FailedToAdd2:
- FailedToAdd3:
- FailedToCreateIMMirror:
- FailedToAdd4:
- FailedToAdd5:
- FailedToAdd6:
- FailedToCreateArcMirror:
- FailedToDoMirrorInit:
-
- CloseComponent (urlInstance);
- printf ("Error: %d\n", theErr);
-
- return;
-
- }
-
- /**
- * StrPrint
- *
- * Dump a string to printf...
- *
- **/
- char * StrPrint (StringPtr str)
- {
-
- static char string[256];
-
- BlockMove (str+1, string, str[0]);
- string[str[0]] = '\0';
- return string;
- }
-
- /**
- * FullSub
- *
- * Given a string, do the complete parse by accessing the URL Helper compontent
- * directly.
- *
- **/
- void FullSub (ComponentInstance urlInstance, StringPtr string)
- {
- OSErr theErr;
- Str255 newURL;
- short index;
- URLHParseRef parseRef;
-
- printf ("Full Test on: '%s'\n", StrPrint(string));
-
- /**
- ** Now, given a random URL, loop over all the mirrors... :)
- **/
-
- theErr = URLHNewParseState (urlInstance, string, &parseRef);
- if (theErr != noErr) {
- printf ("Error parsing state: %d\n", theErr);
- return;
- }
-
- theErr = 0;
- index = 1;
- while (theErr == noErr) {
- theErr = URLHGetMirrorRep (urlInstance, parseRef, newURL, index);
- if (theErr == noErr)
- printf (" -> '%s'\n", StrPrint(newURL));
- index++;
- }
-
- URLHDisposeParseState (urlInstance, parseRef);
-
- return;
- }
- /**
- * Lib1Sub
- *
- * Use the library to get the primary miirror back
- **/
- void Lib1Sub (StringPtr string)
- {
- Str255 mirror;
-
- printf ("Getting primary mirror for '%s'\n", StrPrint(string));
- URLHLibGetFirstMirror (string, mirror);
- printf ("And it is: '%s'\n", StrPrint(mirror));
- }
-
- void LibAllSub (StringPtr string)
- {
- short index;
- URLHParseRef parseRef;
- Str255 mirror;
-
- printf ("Getting all mirrors for '%s'\n", StrPrint(string));
- parseRef = URLHLibNewParseState (string);
- index = 1;
- while (URLHLibGetIndexedMirror (parseRef, index, mirror)) {
- printf ("-> '%s'\n", StrPrint(mirror));
- index++;
- }
- URLHLibDisposeParseState (parseRef);
- }
-